#!/usr/bin/env python

# -------------------------------
# projects/python/collatz/main.py
# Copyright (C) 2009
# Glenn P. Downing
# -------------------------------

# To run the program
#     main.py < Collatz.in > Collatz.out

# To document the program
#     pydoc -w main

import types

# -------
# globals
# -------
i = 0 # input: don't change after reading
j = 0 # input: don't change after reading
v = 0 # output
cache = {} # lazy cache. filled as we go

# -----------
# InputReader
# -----------
"""
Class to read input from the standard in
"""
class InputReader (object) :
    def read (self) :
        return raw_input()

# ------------
# OutputWriter
# ------------
"""
Class to write output to standard out
"""
class OutputWriter (object) :
    def write (self, *a) :
        for w in a :
            print w,
        print

# -------
# my_read
# -------

def my_read (r) :
    """
    reads an int into i and j
    return true if that succeeds, false otherwise
    """
    global i
    global j
    try :
        s = r.read()
    except EOFError :
        return False
    l = s.split()
    i = int(l[0])
    j = int(l[1])
    return True

# -------
# my_eval
# -------

def cycle_length (n) :
    """
    recursively calculates the cycle length of n for the 3n + 1 problem.
    this function uses and adds to the global cache.
    
    cycle length of 1 is defined as 1 (per UVA)
    
    n is even => cycle_length (n) = 1 + cycle_length(n / 2)
    n is odd => cycle_length (n) = 2 + cycle_length( n + (n >> 1) + 1 )
        nb: this is a shortcut for speed optimization. if we have odd n that isn't one, we'll multiply by 3n+1, which yields an even, then divide by 2.
        
    @param n the number to find the cycle length for
    @return the cycle length
    """
    assert type(n) is types.IntType or type(n) is types.LongType
    assert n >= 1
    
    value = cache.get(n, -1) #-1 is the value if we don't find n in the cache.
    
    # if we've already cached n, then return that
    if value >= 1 :
        return value
    
    # otherwise, if n equals 1, return 1 per the UVA spec
    if n == 1 :
        return 1
    
    if n % 2 == 0 :
        # if n is even, compute the 3n+1
        # solution to n/2
        value = 1 + cycle_length(n >> 1)
    else :
        # if n is odd, do a two-step computation
        # (3n+1)/2
        value = 2 + cycle_length(n + (n >> 1) + 1)
    
    assert value >= 1 # minimum length of a cycle
    assert not type(value) is types.FloatType
    
    # finally, cache and return the value
    cache[n] = value
    return value

def my_eval () :
    """
    computes the max cycle length in the range [i, j]
    and stores the result in v
    """
    global v
    
    temp = 0
    
    assert type(i) is types.IntType
    assert type(j) is types.IntType
    assert i > 0
    assert j > 0
    
    # range(a,b) is exclusive, so add one to both to make it inclusive
    for x in xrange(min(i,j),max(i+1,j+1)) :
        temp = max(cycle_length(x), temp)
    v = temp

# --------
# my_print
# --------

def my_print (w) :
    """
    writes the values of i, j, and v
    """
    w.write(i, j, v)

# ----
# main
# ----

def main () :
    """
    runs the program
    """
    while my_read(InputReader()) :
        my_eval()
        my_print(OutputWriter())

if __name__ == "__main__" :
    main()

